{extend name="../../base/view/common/base" /}
{block name="breadcrumb"}
<span class="layui-breadcrumb">
  <a href="https://www.gougucms.com/" target="_blank">勾股DEV</a>
  <a href="/home/user/setting">信息设置</a>
  <a><cite>系统配置</cite></a>
</span>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="main-content">
	{include file="../../base/view/common/submenu" /}
	<div class="main-page-content">
		<div class="layui-form-bar">
			<button class="layui-btn layui-btn-normal layui-btn-sm add-conf">+ 添加配置项</button>
		</div>
		<table class="layui-hide" id="test" lay-filter="test"></table>
	</div>
</div>
<script type="text/html" id="status">
	<i class="layui-icon {{#  if(d.status == 1){ }}layui-icon-ok{{#  } else { }}layui-icon-close{{#  } }}"></i>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	function init(layui) {
		var table = layui.table,
			gougu = layui.gougu,
			form = layui.form;

		layui.pageTable = table.render({
			elem: '#test',
			title: '配置列表',
			url: "/admin/conf/index",
			page: true, //开启分页				
			limit: 20,
			cols: [
				[{
					field: 'id',
					width: 80,
					title: 'ID编号',
					align: 'center'
				},{
					field: 'title',
					width: 200,
					title: '配置名称'
				}, {
					field: 'name',
					title: '配置标识（新增的模板文件名称需与标识名称一致）'
				},{
					field: 'status',
					width: 80,
					title: '状态',
					templet: '#status',
					align: 'center'
				}, {
					width: 160,
					title: '操作',
					align: 'center',
					templet: function (d) {
						var html = '<div class="layui-btn-group"><button class="layui-btn layui-btn-xs" lay-event="add">修改</button><button class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit" >编辑配置</button><button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></div>';
						return html;
					}
				}]
			]
		});
		
		//表头工具栏事件
		$('.add-conf').on('click', function(){
			gougu.open('/admin/conf/add');
		});
		//监听行工具事件
		table.on('tool(test)', function(obj){
			var data = obj.data;
			if(obj.event === 'add'){
				gougu.open('/admin/conf/add?id='+data.id);
				
			}
			if(obj.event === 'edit'){
				gougu.open('/admin/conf/edit?id='+data.id);
			}
			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', {
					icon: 3,
					title: '提示'
				}, function (index) {				
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					gougu.delete('/admin/conf/delete',{ id: obj.data.id },callback);
					layer.close(index);
				});
			}
			return;
		});
	}
</script>
{include file="../../base/view/common/layui" base="base" extend="['gougu']" callback="init" /}
{/block}
<!-- /脚本 -->